/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * @author yaoyuming
 * @date  2020-03-16 17:06
 */
package com.yao.fin.entity.qo;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.yao.fin.entity.dto.FinancialTemplateDto;
import lombok.Data;

import java.io.Serializable;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;

/**
 * 前端分页查询条件
 * @author yaoyuming
 * @date 2020/03/16 17:06
 */
@Data
public class FinancialTemplateQo implements Serializable {

    private LocalDate beginDate;

    private LocalDate endDate;

    private Integer label;

    /**
      * 1-下一周
      */
    private Integer dateType;

    private List<OrderItem> orders;


    public FinancialTemplateQo buildParams(){
        if(null != this.dateType && 0 != this.dateType){
            LocalDate currentDate = LocalDate.now();

            // 下周的今天
            LocalDate sameDateNextWeek = currentDate.plusWeeks(1);

            // 下周的周一
            LocalDate monday = sameDateNextWeek.with(DayOfWeek.MONDAY);

            // 下周的周五
            LocalDate friday = sameDateNextWeek.with(DayOfWeek.FRIDAY);

            beginDate = monday;

            endDate = friday;
        }

        return this;
    }

    public FinancialTemplateDto to(FinancialTemplateQo qo){
        FinancialTemplateDto dto = new FinancialTemplateDto();
        BeanUtil.copyProperties(qo, dto);
        return dto;
    }

}